package io.lkt.modules.sys.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import io.lkt.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.lkt.modules.sys.entity.BUserCommodityInfoEntity;
import io.lkt.modules.sys.service.BUserCommodityInfoService;
import io.lkt.common.utils.PageUtils;
import io.lkt.common.utils.R;



/**
 * 用户商品信息表
 *
 * @author xss
 * @email dustwas@163.com
 * @date 2019-03-12 16:54:01
 */
@RestController
@RequestMapping("/sys/busercommodityinfo")
public class BUserCommodityInfoController {
    @Autowired
    private BUserCommodityInfoService bUserCommodityInfoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:busercommodityinfo:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bUserCommodityInfoService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:busercommodityinfo:info")
    public R info(@PathVariable("id") Integer id){
        BUserCommodityInfoEntity bUserCommodityInfo = bUserCommodityInfoService.getById(id);

        return R.ok().put("bUserCommodityInfo", bUserCommodityInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:busercommodityinfo:save")
    public R save(@RequestBody BUserCommodityInfoEntity bUserCommodityInfo){
        bUserCommodityInfoService.save(bUserCommodityInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:busercommodityinfo:update")
    public R update(@RequestBody BUserCommodityInfoEntity bUserCommodityInfo){
        ValidatorUtils.validateEntity(bUserCommodityInfo);
        bUserCommodityInfo.setModifyTime(new Date());
        bUserCommodityInfoService.updateById(bUserCommodityInfo);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:busercommodityinfo:delete")
    public R delete(@RequestBody Integer[] ids){
        bUserCommodityInfoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
